package jmm;

import jdk.internal.org.objectweb.asm.FieldVisitor;

import javax.swing.text.FieldView;
import java.lang.reflect.Field;

/**
 * @author Brook
 */
public class FileVisibility {

    int a=1;
    int b=2;

    public static void main(String[] args) {

        while (true) {
            FileVisibility fileVisibility = new FileVisibility();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    fileVisibility.change();
                }
            }).start();

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    fileVisibility.print();
                }
            }).start();
        }

    }

    private void change() {
        a=3;
        b=a;
    }

    private void print() {
        System.out.println("b= "+b+ ";a="+a);
    }
}
